package com.justgame.project.service.system.controller;

import com.justgame.project.cloud.common.constant.Result;
import com.justgame.project.service.api.dto.SysDictDTO;
import com.justgame.project.service.system.service.SysDictService;
import lombok.AllArgsConstructor;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/dict")
@AllArgsConstructor
public class SysDictController {
    private final SysDictService sysDictService;

    @GetMapping("/by-code")
    public Result<?> getDictByCode(String code) {
        return Result.OK(sysDictService.getDictByCode(code));
    }


    @GetMapping("/by-parent")
    public Result<?> getDictByParentId(String parentId) {
        return Result.OK(sysDictService.getDictByParentId(parentId));
    }

    @GetMapping("/by-key-code")
    public Result<?> getDictByCodeKey(String code, String key) {
        return Result.OK(sysDictService.getDictByCodeKey(code, key));
    }

    @PostMapping("/save")
    @RequiresRoles("admin")
    public Result<?> insertDict(@RequestBody SysDictDTO dto) {
        return Result.OK(sysDictService.insertDict(dto));
    }

    @PostMapping("/update")
    @RequiresRoles("admin")
    public Result<?> updateDictById(@RequestBody SysDictDTO dto) {
        return Result.OK(sysDictService.updateDictById(dto));
    }

}
